
using System;
using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.EventSystems;                     //事件系统

namespace kernal
{

	public class EventTriggerListener : UnityEngine.EventSystems.EventTrigger

	{
        
        public delegate void VoidDelegate(GameObject go);
        public VoidDelegate onClick;

        public VoidDelegate onDown;

        public VoidDelegate onEnter;
        public Action<GameObject, PointerEventData > onEnterPoint;
     
        public VoidDelegate onExit;
        
        public VoidDelegate onUp;

        public VoidDelegate onSelect;

        public VoidDelegate onUpdateSelect;

 

        /// <summary>

        /// 得到“监听器”组件

        /// </summary>

        /// <param name="go">监听的游戏对象</param>

        /// <returns>

        /// 返回监听器

        /// </returns>

        public static EventTriggerListener Get(GameObject go)

        {

            EventTriggerListener lister = go.GetComponent<EventTriggerListener>();

            if (lister==null)

            {

                lister = go.AddComponent<EventTriggerListener>();

            }

 

            return lister;

 

        }

 

        public override void OnPointerClick(PointerEventData eventData)

        {

            if (onClick!=null)

            {

                onClick(gameObject);

            }

        }

 

        public override void OnPointerDown(PointerEventData eventData)

        {

            if (onDown != null)

            {

                onDown(gameObject);

            }

        }

 

        public override void OnPointerEnter(PointerEventData eventData)

        {

            if (onEnter != null)

            {

                onEnter(gameObject);

            }

            if (onEnterPoint != null)
            {
                onEnterPoint(gameObject,eventData);
            }

        }

 

        public override void OnPointerExit(PointerEventData eventData)

        {

            if (onExit != null)

            {

                onExit(gameObject);

            }

        }

 

        public override void OnPointerUp(PointerEventData eventData)

        {

            if (onUp != null)

            {

                onUp(gameObject);

            }

        }

 

        public override void OnSelect(BaseEventData eventData)

        {

            if (onSelect != null)

            {

                onSelect(gameObject);

            }

        }

 

        public override void OnUpdateSelected(BaseEventData eventData)

        {

            if (onUpdateSelect != null)

            {

                onUpdateSelect(gameObject);

            }

        }

 

 

 

    }//class_end

}
